package com.janedler.jtoast;

import android.content.Context;
import android.util.Log;

import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque;


/**
 * @author janedler
 * @ClassName: com.example.lij8926.customtoastdemo
 * @Description: CFPToast管理类
 * @date 2016/3/9 12:50
 */
public class CFPToastManager {

    private static final LinkedBlockingDeque<CFPToast.ToastEntity> mQueue = new LinkedBlockingDeque(128);

    private static class CFPToastManagerHolder {
        private static CFPToastManager instance = new CFPToastManager();
    }

    public static CFPToastManager getInstance() {
        return CFPToastManagerHolder.instance;
    }

    private CFPToastManager() {
    }

    public void enqueueToast(Context context, final CFPToast.ToastEntity entity, int duration) {
        if (entity == null) {
            return;
        }
        mQueue.offer(entity);
        Log.e("Thread", "mQueue size " + mQueue.size());
        //检查并通知CFPToastService开始工作
        CFPToastService.getInstance().notifiyAndCheckToastRuning();
    }

    public LinkedBlockingDeque<CFPToast.ToastEntity> getQueue() {
        Log.e("Thread", "mQueue size >> " + mQueue.size());
        return mQueue;
    }


    public void cleanQueue() {
        if (mQueue == null || mQueue.isEmpty()) {
            return;
        }
        mQueue.clear();
    }


}
